package com.example.jobback.controller.recruiter;

import com.example.jobback.req.common.page.PageReq;
import com.example.jobback.req.recruiter.company.profile.CompanyReq;
import com.example.jobback.req.recruiter.employee.create.EmployeeCreatedReq;
import com.example.jobback.req.recruiter.profile.RecruiterReq;
import com.example.jobback.resp.recruiter.company.employee.GetCompanyEmployeeResp;
import com.example.jobback.resp.recruiter.company.message.RCrossComMessageResp;
import com.example.jobback.resp.recruiter.company.page.RCrossGetPageCompanyListResp;
import com.example.jobback.resp.recruiter.profile.RecruiterCompanyResp;
import com.example.jobback.result.Result;
import com.example.jobback.service.recruiter.RecruiterCompanyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @ClassName: RecruiterCompanyController
 * @Description:招聘者-公司控制器
 * @Author: lhb
 * @Date: 2025/6/21
 */
@RestController
@RequestMapping("/recruiter/company")
@Tag(name = "招聘者-公司控制器",description = "招聘者公司服务对应的相关接口")
public class RecruiterCompanyController {
    private final RecruiterCompanyService recruiterCompanyService;

    public RecruiterCompanyController(RecruiterCompanyService recruiterCompanyService) {
        this.recruiterCompanyService = recruiterCompanyService;
    }


    @Operation(summary = "获取公司招聘者基本信息",description = "无参数")
    @GetMapping("/getBasicMessage")
    @ApiResponse(description = "返回公司招聘者响应体")
    public Result<RecruiterCompanyResp> getBasicMessage(){
        return recruiterCompanyService.getBasicMessage();
    }


    @Operation(summary = "获取指定公司招聘者基本信息",description = "跨服务被调用方,招聘端和求职端共用")
    @ApiResponse(description = "返回公司招聘者响应体")
    @PostMapping("/getRecruiterBasicMessage")
    public Result<RecruiterCompanyResp> getRecruiterBasicMessage(@Parameter(description = "指定用户的userId", required = true)
                                                                 @RequestParam Long userId){
        return recruiterCompanyService.getRecruiterBasicMessage(userId);
    }

    @Operation(summary = "获取指定公司招聘者基本信息", description = "跨服务被调用方,管理员端使用",hidden = true)
    @ApiResponse(description = "返回公司招聘者响应体")
    @PostMapping("/getRecruiterBasicMessageForAdmin")
    public Result<RecruiterCompanyResp> getRecruiterBasicMessageForAdmin(
            @Parameter(description = "指定用户的userId", required = true)
            @RequestParam Long userId) {
        return recruiterCompanyService.getRecruiterBasicMessageForAdmin(userId);
    }



    @Operation(summary = "编辑基本信息",description = "修改招聘者基本信息，公司信息修改是另外的接口")
    @ApiResponse(description = "返回token，前端更新token，重新执行getBasicMessage")
    @PostMapping("/editBasicMessage")
    public Result<Object> editBasicMessage(@Validated
                                           @RequestBody
                                           RecruiterReq req) throws Exception {
        return recruiterCompanyService.editBasicMessage(req);
    }


    @Operation(summary = "上传头像",description = "上传头像，个人头像，公司头像是别的接口")
    @PostMapping("/uploadAvatar")
    @ApiResponse(description = "返回token，前端更新token，重新执行getBasicMessage")
    public Result<Object> uploadAvatar(@RequestBody
                                       @Parameter(description = "头像文件", required = true)
                                       MultipartFile file){
        return recruiterCompanyService.uploadAvatar(file);
    }

    @Operation(summary = "上传公司头像",description = "上传公司头像，只有boss有权限")
    @PostMapping("/uploadCompanyAvatar")
    @ApiResponse(description = "返回token，前端更新token，重新执行getBasicMessage")
    public Result<Object> uploadCompanyAvatar(@RequestBody
                                              @Parameter(description = "头像文件", required = true)
                                              MultipartFile file){
        return recruiterCompanyService.uploadCompanyAvatar(file);
    }

    @Operation(summary = "编辑公司基本信息",description = "修改公司信息")
    @ApiResponse(description = "返回token，前端更新token")
    @PostMapping("/editCompanyBasicMessage")
    public Result<Object> editCompanyBasicMessage(@Validated
                                                  @RequestBody
                                                  CompanyReq req){
        return recruiterCompanyService.editCompanyBasicMessage(req);
    }


    @Operation(summary = "编辑公司关键信息",description = "修改关键公司信息，boss才有权限修改")
    @ApiResponse(description = "返回token，前端更新token")
    @PostMapping("/editCompanyCoreMessage")
    public Result<Object> editCompanyCoreMessage(@RequestParam
                                                 @Parameter(description = "公司全称", required = true, example = "阿里巴巴集团")
                                                 @NotBlank(message = "公司名称不能为空") String companyName,
                                                 @RequestParam
                                                 @Parameter(description = "公司成立日期", required = true, example = "1999-04-04T00:00:00")
                                                 @NotNull(message = "创建日期不能为空")
                                                 LocalDateTime createDate){
        return recruiterCompanyService.editCompanyCoreMessage(companyName,createDate);
    }

    @Operation(summary = "增设员工",description = "增设员工，boss和管理员才有权限")
    @ApiResponse(description = "返回token，前端更新token")
    @PostMapping("/createEmployee")
    public Result<Object> createEmployee(@Validated
                                         @RequestBody
                                         EmployeeCreatedReq req) {
        return recruiterCompanyService.createEmployee(req);
    }

    @Operation(summary = "获取指定公司信息",description = "跨服务被调用方,管理员端调用",hidden = true)
    @ApiResponse(description = "返回公司基本响应体")
    @PostMapping("/getCompanyMessageForAdmin")
    public Result<RCrossComMessageResp> getCompanyMessageForAdmin(@Parameter(description = "指定公司的id", required = true)
                                                                    @RequestParam Long companyId){
        return recruiterCompanyService.CrossGetCompanyMessageForAdmin(companyId);
    }

    @Operation(summary = "获取公司列表",description = "跨服务调用，被调用方",hidden = true)
    @ApiResponse(description = "无")
    @PostMapping("/getCompanyList")
    public Result<RCrossGetPageCompanyListResp> getCompanyList(@Validated
                                                                   @RequestBody
                                                                   PageReq pageReq){
        return recruiterCompanyService.getCompanyList(pageReq);
    }

    @Operation(summary = "获取本公司员工列表",description = "字段不多，该员工的信息全量返回，也就是无查看详细接口")
    @GetMapping("/getCompanyEmployees")
    @ApiResponse(description = "返回公司员工响应体列表")
    public Result<List<GetCompanyEmployeeResp>> getCompanyEmployees(){
        return recruiterCompanyService.getCompanyEmployees();
    }

    @Operation(summary = "删除员工",description = "只有老板有权限")
    @ApiResponse(description = "返回token")
    @DeleteMapping("/deleteEmployee")
    public Result<Object> deleteEmployee(@Parameter(description = "用户userId", required = true)
                                        @RequestParam Long deleteUserId){
        return recruiterCompanyService.deleteEmployee(deleteUserId);
    }






}
